package beans;

import java.util.ArrayList;



public class Column {

	private ArrayList<Constraint> cons;
	private String name;
	private String type;
	private int size;
	private Table tab;
	private boolean nullable;
	private boolean isNew;
	
	public Column(String aName, String aTab){
		name=aName;
		cons=new ArrayList<Constraint>();
		isNew=false;
		tab=new Table(aTab);
		setNullable(true);
		
	}
	
	public ArrayList<Constraint> getCons() {
		return cons;
	}
	public void setCons(ArrayList<Constraint> cons) {
		this.cons = cons;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Table getTab() {
		return tab;
	}
	public void setTab(Table tab) {
		this.tab = tab;
	}
	public boolean isNew() {
		return isNew;
	}
	public void setNew(boolean isNew) {
		this.isNew = isNew;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public boolean isNullable() {
		return nullable;
	}

	public void setNullable(boolean nullable) {
		this.nullable = nullable;
	}

	@Override
	public String toString() {
		String retour="Column [name=" + name + ", type=" + type + "("+size+") ";
		if(!nullable){
			retour+="NON NULL";
		}
		retour+=" ]";
		return retour;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((tab == null) ? 0 : tab.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Column other = (Column) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (tab == null) {
			if (other.tab != null)
				return false;
		} else if (!tab.equals(other.tab))
			return false;
		/*if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;*/
		return true;
	}
	
}
